package com.GamersCom.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.GamersCom.db.GameRate;
import com.GamersCom.db.GameRateDAO;

public class GameRateMgr
{
	GameRateDAO dao = new GameRateDAO();
	
	public void insert(GameRate gameRate) throws SQLException 
	{
		String query = "insert into GameRates set score = ?, game_id= ?, user_id = ?";
		List paramList = new ArrayList();
		paramList.add(gameRate.getScore());
		paramList.add(gameRate.getGameId());
		paramList.add(gameRate.getUserId());
		
		dao.insert(query, paramList);
	}
	
	public List<GameRate> getRateByUser(int gameId, int userId) throws SQLException
	{
		String query = "select * from gameRates where game_id = ? and user_id = ?";
		List paramList = new ArrayList();
		paramList.add(gameId);
		paramList.add(userId);
		
		return dao.getAll(query, paramList);
	}
	
	public boolean rateExist (int gameId, int userId) throws SQLException
	{
		List<GameRate> list = getRateByUser(gameId, userId);
		
		if ( list != null )
			return true;
		return false;
	}
}
